#!/bin/bash

ISOS_DIR=$(dirname $0)/out
HD_IMG=
SSH_FWD_HOST_PORT=
ISO="$(ls -t $ISOS_DIR/*.iso | head -n 1)"
VIRTIO_NET_DEV="-netdev user,id=vmnic,hostfwd=tcp::$SSH_FWD_HOST_PORT-:22 \
                -device virtio-net,netdev=vmnic"
QEMU="qemu-system-x86_64 -enable-kvm"
MEM="-m 1G"
VIDEO="-vga std"
AUDIO="-soundhw hda "
WM_HIMTS="-display sdl -no-frame" # -show-cursor"
[ "$ISO"               ] && CD="-cdrom $ISO -boot d"                            || CD=''
[ "$HD_IMG"            ] && HD="-drive file=$HD_IMG,format=raw,cache=writeback" || HD=''
[ "$SSH_FWD_HOST_PORT" ] && NET_DEV="$VIRTIO_NET_DEV"                           || NET_DEV=''


[ ! "$ISO" ] && echo "no ISO found in ISOS_DIR: '$ISOS_DIR'" && exit

CMD="$QEMU $MEM $HD $CD $NET_DEV $VIDEO $AUDIO $WM_HIMTS $*"
echo "$CMD" ; $CMD ;
